// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------
// Modification history:
// feature: Support Cache fast application and slow release mechanism
// feature: the default memory policy change from PREALLOCATED_MEMORY_MODE to PREALLOCATED_WITH_REALLOC_MEMORY_MODE
// feature: simplify xml profile
// ------------------------------------------------------------------

#ifndef XMLPARSER_SUBSCRIBERATTRIBUTES_H_
#define XMLPARSER_SUBSCRIBERATTRIBUTES_H_

#include <xmlparser/qos/XMLReaderQos.hpp>
#include <xmlparser/attributes/XMLReaderAttributes.h>
#include <xmlparser/attributes/XMLRTPSParticipantAttributes.h>
#include <deps/common/PropertyPolicy.h>

namespace vbsutil {
namespace xmlparser {

/**
 * Class SubscriberAttributes, used by the user to define the attributes of a Subscriber.
 * @ingroup ERTPS_ATTRIBUTES_MODULE
 */
class SubscriberAttributes {
 public:
    //! Reader QOs.
    ReaderQos qos;

    //! Times for a RELIABLE Reader
    xmlparser::ReaderTimes times;

    //! Unicast locator list
    xmlparser::LocatorList_t unicastLocatorList;

    //! Multicast locator list
    xmlparser::LocatorList_t multicastLocatorList;

    //! Remote locator list
    xmlparser::LocatorList_t remoteLocatorList;

    //! The collection of external locators to use for communication.
    xmlparser::ExternalLocators external_unicast_locators;

    //! Whether locators that don't match with the announced locators should be kept.
    bool ignore_non_matching_locators = false;

    //! Underlying History memory policy
    xmlparser::MemoryManagementPolicy_t historyMemoryPolicy = xmlparser::AUTOMATIC_MEMORY_MODE;

    //! Properties
    xmlparser::PropertyPolicy properties;

    //! Matched publishers allocation limits
    ResourceLimitedContainerConfig matched_publisher_allocation;

    SubscriberAttributes() = default;

    virtual ~SubscriberAttributes() = default;

    bool operator==(const SubscriberAttributes& b) const {
        return (this->qos == b.qos) && (this->times == b.times) && (this->unicastLocatorList == b.unicastLocatorList) &&
               (this->multicastLocatorList == b.multicastLocatorList) &&
               (this->remoteLocatorList == b.remoteLocatorList) &&
               (this->historyMemoryPolicy == b.historyMemoryPolicy) && (this->properties == b.properties);
    }

    bool operator!=(const SubscriberAttributes& b) const { return !(*this == b); }

    /**
     * Get the user defined ID
     * @return User defined ID
     */
    inline int16_t getUserDefinedID() const { return m_userDefinedID; }

    /**
     * Get the entity defined ID
     * @return Entity ID
     */
    inline int16_t getEntityID() const { return m_entityID; }

    /**
     * Set the user defined ID
     * @param id User defined ID to be set
     */
    inline void setUserDefinedID(const uint16_t id) { m_userDefinedID = static_cast<int16_t>(id); }

    /**
     * Set the entity ID
     * @param id Entity ID to be set
     */
    inline void setEntityID(const uint16_t id) { m_entityID = static_cast<int16_t>(id); }

 private:
    //! User Defined ID, used for StaticEndpointDiscovery, default value -1.
    int16_t m_userDefinedID = -1;

    //! Entity ID, if the user want to specify the EntityID of the enpoint, default value -1.
    int16_t m_entityID = -1;
};

}  // namespace xmlparser
}  // namespace vbsutil

#endif
